package nuc.edu.controller;

import nuc.edu.dao.UserDao;
import nuc.edu.entities.Department;
import nuc.edu.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Collection;
import java.util.Map;


/**
 * Created by 张朝亮
 */
@Controller
public class LoginController {

    @Autowired
    private UserDao userDao;

    @PostMapping(value = "/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                         Map<String,Object> map, HttpSession session){
        User user = null;
        if((user = userDao.userLogin(username, password)) != null) {
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";
        }else{
            map.put("msg","用户名密码错误");
            return  "index";
        }

    }

}
